home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / file / objdump.pat / objdump.patch
Encoding:
Text File  |  1994-12-06  |  17.8 KB  |  682 lines

  1.  
  2. Here are some changes I made to objdump which allow it to dump section
  3. contents as raw data.  This is usefull if you need to make an image
  4. of an executable to load into memory with out the help of the 
  5. operating systems.  We use this to make boot images of the Linux
  6. kernel under ELF as well as for dynamic loading of kernel modules.
  7. Another case when they would be useful, is for making ROM Images.
  8.  
  9. I've also enclosed source for another program called encaps which
  10. takes raw data and makes it a .o file.  It's useful for adding 
  11. resources are other data to a program without recompiling.  We use
  12. it to include 16 bit minix assembly in the Linux kernel.
  13.  
  14.     Ross Biro biro@yggdrasil.com
  15.  
  16. ------ CUT HERE ------
  17. ---
  18. *** objdump.c.~1~    Wed Sep 28 13:06:43 1994
  19. --- objdump.c    Mon Nov 14 06:57:47 1994
  20. ***************
  21. *** 15,24 ****
  22. --- 15,28 ----
  23.   
  24.   You should have received a copy of the GNU General Public License
  25.   along with this program; if not, write to the Free Software
  26.   Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  27.   
  28. + /* Added -k, -o, -q options for use with the Linux kernel
  29. +  * 11/94 Ross Biro biro@yggdrasil.com
  30. +  */
  31.   #include "bfd.h"
  32.   #include "sysdep.h"
  33.   #include "getopt.h"
  34.   #include "bucomm.h"
  35.   #include <stdio.h>
  36. ***************
  37. *** 38,47 ****
  38. --- 42,54 ----
  39.   
  40.   extern char *program_version;
  41.   
  42.   int show_version = 0;        /* show the version number */
  43.   int dump_section_contents;    /* -s */
  44. + int dump_section_raw=0;            /* -k */
  45. + int raw_offset=0;               /* -o */
  46. + int quiet=0;            /* -q */
  47.   int dump_section_headers;    /* -h */
  48.   boolean dump_file_header;    /* -f */
  49.   int dump_symtab;        /* -t */
  50.   int dump_dynamic_symtab;    /* -T */
  51.   int dump_reloc_info;        /* -r */
  52. ***************
  53. *** 112,128 ****
  54.   usage (stream, status)
  55.        FILE *stream;
  56.        int status;
  57.   {
  58.     fprintf (stream, "\
  59. ! Usage: %s [-ahifdDrRtTxsl] [-b bfdname] [-m machine] [-j section-name]\n\
  60.          [--archive-headers] [--target=bfdname] [--disassemble]\n\
  61.          [--disassemble-all] [--file-headers] [--section-headers] [--headers]\n\
  62.          [--info] [--section=section-name] [--line-numbers]\n\
  63.          [--architecture=machine] [--reloc] [--full-contents] [--stabs]\n\
  64.          [--syms] [--all-headers] [--dynamic-syms] [--dynamic-reloc]\n\
  65. !        [--version] [--help] objfile...\n\
  66.   at least one option besides -l (--line-numbers) must be given\n",
  67.          program_name);
  68.     exit (status);
  69.   }
  70.   
  71. --- 119,135 ----
  72.   usage (stream, status)
  73.        FILE *stream;
  74.        int status;
  75.   {
  76.     fprintf (stream, "\
  77. ! Usage: %s [-ahifdDkoqrRtTxsl] [-b bfdname] [-m machine] [-j section-name]\n\
  78.          [--archive-headers] [--target=bfdname] [--disassemble]\n\
  79.          [--disassemble-all] [--file-headers] [--section-headers] [--headers]\n\
  80.          [--info] [--section=section-name] [--line-numbers]\n\
  81.          [--architecture=machine] [--reloc] [--full-contents] [--stabs]\n\
  82.          [--syms] [--all-headers] [--dynamic-syms] [--dynamic-reloc]\n\
  83. !        [--version] [--help] [--offset=offset] [--raw] [--quiet] objfile...\n\
  84.   at least one option besides -l (--line-numbers) must be given\n",
  85.          program_name);
  86.     exit (status);
  87.   }
  88.   
  89. ***************
  90. *** 139,148 ****
  91. --- 146,158 ----
  92.     {"full-contents", no_argument, NULL, 's'},
  93.     {"headers", no_argument, NULL, 'h'},
  94.     {"help", no_argument, NULL, 'H'},
  95.     {"info", no_argument, NULL, 'i'},
  96.     {"line-numbers", no_argument, NULL, 'l'},
  97. +   {"offset",  required_argument, NULL, 'o'},
  98. +   {"quiet", no_argument, NULL, 'q'},
  99. +   {"raw", no_argument, NULL, 'k'/* k for kernel */},
  100.     {"reloc", no_argument, NULL, 'r'},
  101.     {"section", required_argument, NULL, 'j'},
  102.     {"section-headers", no_argument, NULL, 'h'},
  103.     {"stabs", no_argument, &dump_stab_section_info, 1},
  104.     {"syms", no_argument, NULL, 't'},
  105. ***************
  106. *** 980,992 ****
  107.         list_matching_formats (matching);
  108.         free (matching);
  109.       }
  110.         return;
  111.       }
  112. !   printf ("\n%s:     file format %s\n", bfd_get_filename (abfd),
  113. !       abfd->xvec->name);
  114.     if (dump_ar_hdrs)
  115.       print_arelt_descr (stdout, abfd, true);
  116.     if (dump_file_header)
  117.       dump_bfd_header (abfd);
  118.     putchar ('\n');
  119. --- 990,1002 ----
  120.         list_matching_formats (matching);
  121.         free (matching);
  122.       }
  123.         return;
  124.       }
  125. !   if (!quiet)
  126. !     printf ("\n%s:     file format %s\n", bfd_get_filename (abfd),
  127. !         abfd->xvec->name);
  128.     if (dump_ar_hdrs)
  129.       print_arelt_descr (stdout, abfd, true);
  130.     if (dump_file_header)
  131.       dump_bfd_header (abfd);
  132.     putchar ('\n');
  133. ***************
  134. *** 1031,1042 ****
  135.       }
  136.   
  137.     if (bfd_check_format (file, bfd_archive) == true)
  138.       {
  139.         bfd *last_arfile = NULL;
  140. !       printf ("In archive %s:\n", bfd_get_filename (file));
  141.         for (;;)
  142.       {
  143.         bfd_set_error (bfd_error_no_error);
  144.   
  145.         arfile = bfd_openr_next_archived_file (file, arfile);
  146. --- 1041,1052 ----
  147.       }
  148.   
  149.     if (bfd_check_format (file, bfd_archive) == true)
  150.       {
  151.         bfd *last_arfile = NULL;
  152. !       if (!quiet)
  153. !     printf ("In archive %s:\n", bfd_get_filename (file));
  154.         for (;;)
  155.       {
  156.         bfd_set_error (bfd_error_no_error);
  157.   
  158.         arfile = bfd_openr_next_archived_file (file, arfile);
  159. ***************
  160. *** 1073,1082 ****
  161. --- 1083,1093 ----
  162.   {
  163.     asection *section;
  164.     bfd_byte *data = 0;
  165.     bfd_size_type datasize = 0;
  166.     bfd_size_type i;
  167. +   int err;
  168.   
  169.     for (section = abfd->sections; section != NULL; section =
  170.          section->next)
  171.       {
  172.         int onaline = 16;
  173. ***************
  174. *** 1084,1128 ****
  175.         if (only == (char *) NULL ||
  176.         strcmp (only, section->name) == 0)
  177.       {
  178.         if (section->flags & SEC_HAS_CONTENTS)
  179.           {
  180. !           printf ("Contents of section %s:\n", section->name);
  181.   
  182.             if (bfd_section_size (abfd, section) == 0)
  183.           continue;
  184.             data = (bfd_byte *) xmalloc ((size_t) bfd_section_size (abfd, section));
  185.             datasize = bfd_section_size (abfd, section);
  186.   
  187.   
  188.             bfd_get_section_contents (abfd, section, (PTR) data, 0, bfd_section_size (abfd, section));
  189.   
  190. !           for (i = 0; i < bfd_section_size (abfd, section); i += onaline)
  191. !         {
  192. !           bfd_size_type j;
  193.   
  194. !           printf (" %04lx ", (unsigned long int) (i + section->vma));
  195. !           for (j = i; j < i + onaline; j++)
  196. !             {
  197. !               if (j < bfd_section_size (abfd, section))
  198. !             printf ("%02x", (unsigned) (data[j]));
  199. !               else
  200. !             printf ("  ");
  201. !               if ((j & 3) == 3)
  202. !             printf (" ");
  203. !             }
  204.   
  205. !           printf (" ");
  206. !           for (j = i; j < i + onaline; j++)
  207. !             {
  208. !               if (j >= bfd_section_size (abfd, section))
  209. !             printf (" ");
  210. !               else
  211. !             printf ("%c", isprint (data[j]) ? data[j] : '.');
  212. !             }
  213. !           putchar ('\n');
  214.           }
  215.             free (data);
  216.           }
  217.       }
  218.       }
  219.   }
  220. --- 1095,1155 ----
  221.         if (only == (char *) NULL ||
  222.         strcmp (only, section->name) == 0)
  223.       {
  224.         if (section->flags & SEC_HAS_CONTENTS)
  225.           {
  226. !           if (!quiet)
  227. !         printf ("Contents of section %s:\n", section->name);
  228.   
  229.             if (bfd_section_size (abfd, section) == 0)
  230.           continue;
  231.             data = (bfd_byte *) xmalloc ((size_t) bfd_section_size (abfd, section));
  232.             datasize = bfd_section_size (abfd, section);
  233.   
  234.   
  235.             bfd_get_section_contents (abfd, section, (PTR) data, 0, bfd_section_size (abfd, section));
  236.   
  237. !           if (dump_section_raw) {
  238. !         if (section->vma < raw_offset) continue;
  239.   
  240. !         if (fseek (stdout, section->vma-raw_offset, SEEK_SET)) {
  241. !           perror ("fseek");
  242. !         }
  243.   
  244. !         err =fwrite (data,1, bfd_section_size (abfd, section), stdout);
  245. !         if (err != bfd_section_size (abfd, section)) {
  246. !           perror ("fwrite");
  247. !           return;
  248.           }
  249. +             
  250. +           } else {
  251. +         for (i = 0; i < bfd_section_size (abfd, section); i += onaline)
  252. +           {
  253. +             bfd_size_type j;
  254. +             printf (" %08lx ", (unsigned long int) (i + section->vma));
  255. +             for (j = i; j < i + onaline; j++)
  256. +               {
  257. +             if (j < bfd_section_size (abfd, section))
  258. +               printf ("%02x", (unsigned) (data[j]));
  259. +             else
  260. +               printf ("  ");
  261. +             if ((j & 3) == 3)
  262. +               printf (" ");
  263. +               }
  264. +             printf (" ");
  265. +             for (j = i; j < i + onaline; j++)
  266. +               {
  267. +             if (j >= bfd_section_size (abfd, section))
  268. +               printf (" ");
  269. +             else
  270. +               printf ("%c", isprint (data[j]) ? data[j] : '.');
  271. +               }
  272. +             putchar ('\n');
  273. +           }
  274. +           }
  275.             free (data);
  276.           }
  277.       }
  278.       }
  279.   }
  280. ***************
  281. *** 1504,1514 ****
  282.     program_name = *argv;
  283.     xmalloc_set_program_name (program_name);
  284.   
  285.     bfd_init ();
  286.   
  287. !   while ((c = getopt_long (argc, argv, "ib:m:VdDlfahrRtTxsj:", long_options,
  288.                  (int *) 0))
  289.        != EOF)
  290.       {
  291.         seenflag = true;
  292.         switch (c)
  293. --- 1531,1541 ----
  294.     program_name = *argv;
  295.     xmalloc_set_program_name (program_name);
  296.   
  297.     bfd_init ();
  298.   
  299. !   while ((c = getopt_long (argc, argv, "kqo:ib:m:VdDlfahrRtTxsj:", long_options,
  300.                  (int *) 0))
  301.        != EOF)
  302.       {
  303.         seenflag = true;
  304.         switch (c)
  305. ***************
  306. *** 1549,1558 ****
  307. --- 1576,1595 ----
  308.       case 'd':
  309.         disassemble = true;
  310.         break;
  311.       case 'D':
  312.         disassemble = disassemble_all = true;
  313. +       break;
  314. +     case 'q':
  315. +       quiet = 1;
  316. +       break;
  317. +     case 'k':
  318. +       dump_section_raw = 1;
  319. +       dump_section_contents = 1;
  320. +       break;
  321. +     case 'o':
  322. +       raw_offset = atoi (optarg);
  323.         break;
  324.       case 's':
  325.         dump_section_contents = 1;
  326.         break;
  327.       case 'r':
  328. ------ CUT HERE ------
  329. *** objdump.1.~1~    Thu Sep 15 21:59:29 1994
  330. --- objdump.1    Mon Nov 14 06:50:42 1994
  331. ***************
  332. *** 29,45 ****
  333. --- 29,52 ----
  334.   .RB "[\|" \-i | \-\-info "\|]" 
  335.   .RB "[\|" "\-j\ "\c
  336.   .I section\c
  337.   .RB " | " "\-\-section="\c
  338.   .I section\c
  339. + .RB "[\|" \-k | \-\-raw "\|]" 
  340.   \&\|] 
  341.   .RB "[\|" \-l | \-\-line\-numbers "\|]"
  342.   .RB "[\|" "\-m\ "\c
  343.   .I machine\c
  344.   .RB " | " "\-\-architecture="\c
  345.   .I machine\c
  346.   \&\|] 
  347. + .RB "[\|" "\-o\ "\c
  348. + .I offset\c
  349. + .RB " | " "\-\-offset="\c
  350. + .I offset\c
  351. + \&\|] 
  352. + .RB "[\|" \-q | \-\-quiet "\|]" 
  353.   .RB "[\|" \-r | \-\-reloc "\|]" 
  354.   .RB "[\|" \-R | \-\-dynamic\-reloc "\|]" 
  355.   .RB "[\|" \-s | \-\-full\-contents "\|]"
  356.   .RB "[\|" \-\-stabs "\|]"
  357.   .RB "[\|" \-t | \-\-syms "\|]" 
  358. ***************
  359. *** 181,190 ****
  360. --- 188,206 ----
  361.   Display information only for section \c
  362.   .I name\c
  363.   \&
  364.   
  365.   .TP
  366. + .B \-k
  367. + .TP
  368. + .B \-\-raw
  369. + Dump all the loadable section contents as raw data on stdout.
  370. + Useful for making
  371. + boot images or turning an executable into raw data.  Some architectures
  372. + (such as elf) require that stdout be seekable for this to work.
  373. + .TP
  374.   .B \-l
  375.   .TP
  376.   .B \-\-line\-numbers
  377.   Label the display (using debugging information) with the filename
  378.   and source line numbers corresponding to the object code shown.
  379. ***************
  380. *** 202,211 ****
  381. --- 218,240 ----
  382.   .I machine\c
  383.   \&.  You can list available architectures using the `\|\c
  384.   .B \-i\c
  385.   \|'
  386.   option. 
  387. + .TP
  388. + .BI "\-o " "offset"\c
  389. + .TP
  390. + .BI "\-\-offset=" "offset"\c
  391. + \&
  392. + The offset to make byte 0 of a raw dump.
  393. + .TP
  394. + .B \-q
  395. + .TP
  396. + .B \-\-quiet
  397. + Supress most informational messages, useful with \fB\-k\fP.
  398.   
  399.   .TP
  400.   .B \-r
  401.   .TP
  402.   .B \-\-reloc
  403. ------ CUT HERE ------
  404. /* encaps.c */
  405. /* Copyright (C) 1994 Yggdrasil Computing, Incorporated
  406.    4880 Stevens Creek Blvd. Suite 205
  407.    San Jose, CA 95129-1034
  408.    USA
  409.    Tel (408) 261-6630
  410.    Fax (408) 261-6631
  411.  
  412.    Encaps is free software; you can redistribute it and/or modify
  413.    it under the terms of the GNU General Public License as published by
  414.    the Free Software Foundation; either version 2, or (at your option)
  415.    any later version.
  416.  
  417.    You should have received a copy of the GNU General Public License
  418.    along with this program; see the file COPYING.  If not, write to
  419.    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  420.  
  421. /* Written by Ross Biro Nov 94 */ 
  422.  
  423. #include <stdlib.h>
  424. #include <stdio.h>
  425. #include <fcntl.h>
  426. #include <malloc.h>
  427. #include <errno.h>
  428. #include <sys/types.h>
  429. #include <sys/stat.h>
  430. #include <sys/mman.h>
  431. #include <unistd.h>
  432. #include <getopt.h>
  433.  
  434. #include "ansidecl.h"
  435. #include <bfd.h>
  436.  
  437. #define obstack_chunk_alloc malloc
  438. #define obstack_chunk_free free
  439.  
  440. #define DEF_SEC_FLAGS SEC_ALLOC|SEC_LOAD|SEC_RELOC|SEC_HAS_CONTENTS
  441.  
  442. /* This is the routine that does most of the work. */
  443. /* file is the name of the output file 
  444.    target is the target type "a.out-i386-linux" for example
  445.    secflags is ored with DEFAULT_SEC_FLAGS and then applied.
  446.             It is used to say if the section is data or code. (Normally 
  447.         SEC_DATA.
  448.    format  is the file format to write (Normally bfd_object)
  449.    symname is the name to give the symbol.
  450.    secname is the name of the section (.data is good)
  451.    fd      is the file descriptor for the data to be put in the file. 
  452. */
  453.  
  454. int
  455. encapsulate (const char *file, const char *target, unsigned long secflags,
  456.          bfd_format format, const char *symname,  char *lengthname,
  457.          const char *secname,
  458.          int fd) {
  459.   bfd *abfd;
  460.   asection *sec;
  461.   size_t length;
  462.   unsigned char *ptr;
  463.   struct stat st;
  464.   asymbol *syms[3];
  465.   asymbol *new;
  466.  
  467.   bfd_init();
  468.   bfd_check_init();
  469.  
  470.   abfd = bfd_openw(file, target);
  471.   
  472.   if (abfd == NULL) {
  473.     fprintf (stderr, "Error Openning %s file %s: %s\n",target, file, 
  474.          bfd_errmsg (bfd_get_error()));
  475.     return (bfd_get_error()<<16| errno);
  476.   }
  477.  
  478. #ifdef __i386__  
  479.   /* This wonderful poorly document call is absolutely necessary. */
  480.   /* The linker deals with this in a much better way.  Perhaps the
  481.      code should be borowed. */
  482.   bfd_default_set_arch_mach (abfd, bfd_arch_i386, 0);
  483. #endif
  484.  
  485.   if (!bfd_set_format (abfd, format)) {
  486.     fprintf (stderr, "Error settting format: %s\n",
  487.          bfd_errmsg (bfd_get_error()));
  488.     return (bfd_get_error()<<16| errno);
  489.   }
  490.  
  491.   sec = bfd_make_section (abfd, secname);
  492.  
  493.   if (sec == NULL) {
  494.     fprintf (stderr, "Error Making Section: %s\n",
  495.          bfd_errmsg (bfd_get_error()));
  496.     return (bfd_get_error()<<16| errno);
  497.   }
  498.  
  499.   if (!bfd_set_section_flags(abfd, sec, DEF_SEC_FLAGS | secflags)) {
  500.     fprintf (stderr, "Error settting section flags %s\n",
  501.          bfd_errmsg (bfd_get_error()));
  502.     return (bfd_get_error()<<16| errno);
  503.   }
  504.   
  505.   /* We are ready for the data. */
  506.   if (fstat (fd, &st)) {
  507.     fprintf (stderr, "Error Stating Data File: %s\n", 
  508.          strerror (errno));
  509.     return (errno);
  510.   }
  511.   
  512.   length = st.st_size;
  513.  
  514.   /* create a new symbol */
  515.  
  516.   new = bfd_make_empty_symbol (abfd);
  517.   if ((unsigned long)new < 4096) {
  518.     fprintf (stderr, "Error allocating symbol: %s\n",
  519.          bfd_errmsg (bfd_get_error()));
  520.     return (bfd_get_error()<<16| errno);
  521.   }
  522.  
  523.   new->name = symname;
  524.   new->section = sec;
  525.   new->flags = BSF_EXPORT;
  526.   new->value =sizeof (char *);
  527.   syms[0]=new;
  528.  
  529.  
  530.   new = bfd_make_empty_symbol (abfd);
  531.   if ((unsigned long)new < 4096) {
  532.     fprintf (stderr, "Error allocating symbol: %s\n",
  533.          bfd_errmsg (bfd_get_error()));
  534.     return (bfd_get_error()<<16| errno);
  535.   }
  536.  
  537.   new->name = lengthname;
  538.   new->section = sec;
  539.   new->flags = BSF_EXPORT;
  540.   new->value =0;
  541.   syms[1]=new;
  542.  
  543.   syms[2]=NULL;
  544.  
  545.   if (!bfd_set_symtab (abfd, syms, 2)) {
  546.     fprintf (stderr, "Error setting symbol table: %s\n",
  547.          bfd_errmsg (bfd_get_error()));
  548.     return (bfd_get_error()<<16| errno);
  549.   }
  550.  
  551.   /* mmap would be good here, but if I do it, I can't easily
  552.      add the length info.  Oh well
  553.   ptr = mmap (0, length, PROT_READ, MAP_FILE|MAP_SHARED,  fd, 0); 
  554.  
  555.   if (ptr == NULL) {
  556.     fprintf (stderr, "Error mmapping Data File: %s\n", 
  557.          strerror (errno));
  558.     return (errno);
  559.   }
  560. */
  561.   ptr = malloc (length + sizeof (char *));
  562.  
  563.   if (ptr == NULL) {
  564.     fprintf (stderr, "Error allocating memory for data file: %s\n", 
  565.          strerror (errno));
  566.     return (errno);
  567.   }
  568.  
  569.   /* this is technically a bug.  For example a ctrl-z bg may break this. */
  570.   if (read (fd, ptr+sizeof (char *), length) != length) {
  571.     fprintf (stderr, "Error reading file: %s\n", 
  572.          strerror (errno));
  573.     return (errno);
  574.   }
  575.   *(unsigned long*)ptr = length;
  576.  
  577.   if (! bfd_set_section_size (abfd, sec, length+sizeof(char *))) {
  578.     fprintf (stderr, "Error settting section size %s:\n",
  579.          bfd_errmsg (bfd_get_error()));
  580.     return (bfd_get_error()<<16| errno);
  581.   }
  582.  
  583.   if (! bfd_set_section_contents (abfd, sec, ptr, 0, length+sizeof (char *))) {
  584.     fprintf (stderr, "Error settting section contents: %s\n",
  585.          bfd_errmsg (bfd_get_error()));
  586.     return (bfd_get_error()<<16| errno);
  587.   }
  588.  
  589.   /* write out everything. */
  590.   bfd_close (abfd);
  591.   return (0);
  592. }
  593.  
  594. void 
  595. usage (char *name) {
  596.   fprintf (stderr, "usage %s: [-f format] [-n secname] [-t target] [-s secflags] output-file input-file symbol-name length-name\n", name);
  597.   fpritnf (stderr,"    --format format        file format to write.\n");
  598.   fpritnf (stderr,"    --section_name         name of the section (normally .data)\n");
  599.   fpritnf (stderr,"    --target target        target name (a.out-linux-i386 elf32-i386)\n");
  600.   fpritnf (stderr,"    --sectionflags flags   flags to put in section header\n");
  601.   exit (1);
  602.        
  603. }
  604.  
  605.  
  606. int main (int argc, char *argv[]) {
  607.   int c;
  608.   char *outfile=NULL;
  609.   char *infile=NULL;
  610.   char *target="a.out-i386-linux";
  611.   int secflags = SEC_DATA;
  612.   bfd_format format = bfd_object;
  613.   char *symname = NULL;
  614.   char *lengthname = NULL;
  615.   char *secname = ".data";
  616.   int fd = -1;
  617.  
  618.   int option_index;
  619.   static struct option long_options[] = {
  620.     {"help", 0, 0, 'h'},
  621.     {"format", 1, 0, 'f'},
  622.     {"section-name", 1, 0, 'n'},
  623.     {"target", 1, 0, 't'},
  624.     {"sectionflags", 1, 0, 's'},
  625.   };
  626.   
  627.   while ((c = getopt_long (argc, argv, "hf:t:n:s:",
  628.                long_options, &option_index)) > 0) {
  629.     switch (c) {
  630.     case 'h':
  631.     case '?':
  632.     default:
  633.       usage(argv[0]);
  634.  
  635.     case 'f':
  636.       format = atoi(optarg);
  637.       break;
  638.  
  639.     case 'n':
  640.       secname = optarg;
  641.       break;
  642.  
  643.     case 't':
  644.       target = optarg;
  645.       break;
  646.  
  647.     case 's':
  648.       secflags=atoi (optarg);
  649.       break;
  650.  
  651.     }
  652.   }
  653.   if (argc - optind != 4) usage(argv[0]);
  654.  
  655.   outfile = argv[optind];
  656.   infile= argv[optind+1];
  657.   symname = argv[optind+2];
  658.   lengthname = argv[optind+3];
  659.   fd = open (infile, O_RDONLY);
  660.   if (fd < 0) {
  661.     fprintf (stderr, "error opening infile %s: %s\n", infile,
  662.          strerror(errno));
  663.     exit (1);
  664.   }
  665.  
  666.   if (encapsulate (outfile, target, secflags, format, symname, lengthname, 
  667.            secname, fd))
  668.     return (1);
  669.  
  670.   return (0);
  671. }
  672.  
  673.  
  674.